var $searchBtn,
	$searchForm;
var map;

var RESULT,
	PARAM;

var renderMap = function() {
    map.clearOverlays();
    var points = [];
	$.each(RESULT.list, function(i, waiter) {
        var loc = waiter.loc;
        var point = new BMap.Point(loc[0], loc[1]);
        points.push(point);
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
	});
    map.setViewport(points);
};

var init = function() {
	$searchBtn = $('.search-btn');
	$searchForm = $('.search-form');
    map = new BMap.Map("map");
    var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
    map.addControl(top_left_navigation);

	// 查询
	$searchBtn.click(function(event) {
		PARAM = $('form.search-form').serialize();
		getWaiters(PARAM, function(err, result) {
			RESULT = result;
			renderMap();
		});
	}).click();
}
$(init);
